package com.humanminoritygame.model;

import java.util.Random;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name="SystemUser")
public class User extends PersistentEntity implements Comparable<User> {
	
  @Column(unique=true)
  private String name;
  private String password, mail;
  private Boolean robot = false;
  private UserType type = UserType.PLAYER;
  private Integer confirmedMail = 0;
  

  User() {
  }

  public User(String name, String password, String mail) {
    super();
    this.name = name;
    this.password = password;
    this.mail = mail;
    Random r = new Random();
    this.confirmedMail = Math.abs(r.nextInt());
  }

  public String getName() {
    return name;
  }

  public String getPassword() {
    return password;
  }

  public String getMail() {
    return mail;
  }


  public void setPassword(String password) {
    this.password = password;
  }

  public void setMail(String mail) {
    this.mail = mail;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((name == null) ? 0 : name.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    return super.equals(obj);
  }

  @Override
  public int compareTo(User o) {
    return this.name.compareTo(o.getName());
  }

  public Boolean isRobot() {
    return robot;
  }
  
  public void setRobot() {
    this.robot = true;
  }
  
  public void unsetRobot() {
    this.robot = false;
  }

  public UserType getType() {
    return type;
  }

  public void setType(UserType type) {
    this.type = type;
  }

  public boolean isAdmin() {
    return type == UserType.ADMIN;
  }
  
  public boolean isResearcher(){
    return type == UserType.RESEARCHER;
  }
  
  public boolean isAdminOrResearcher(){
    return isAdmin() || isResearcher();
  }

  public void setConfirmedMail(Integer confirmedMail) {
    this.confirmedMail = confirmedMail;
  }

  public Integer getConfirmedMail() {
    return confirmedMail;
  }

  public void setName(String name) {
    this.name = name;
  }
  public String getHumanity(){
    if( isRobot()){
      return "Robot";
    }
    return "Human";
  }
  
}
